package cn.com.coding.system.service.impl;

import cn.com.coding.common.utils.PageUtil;
import cn.com.coding.common.utils.Query;
import cn.com.coding.system.dao.SysRoleDao;
import cn.com.coding.system.domin.SysRoleEntity;
import cn.com.coding.system.service.SysRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("sysRoleService")
public class SysRoleServiceImpl extends ServiceImpl<SysRoleDao, SysRoleEntity> implements SysRoleService {

    @Override
    public PageUtil queryPage(Map<String, Object> params) {
        IPage<SysRoleEntity> page = this.page(
                new Query<SysRoleEntity>().getPage(params),
                new QueryWrapper<SysRoleEntity>().like("name", params.get("name") != null ? params.get("name") : "")
        );

        return new PageUtil(page);
    }

    @Override
    public List<SysRoleEntity> listRolesByUserPid(String userPid) {
        List<SysRoleEntity> sysRoles = this.list(new QueryWrapper<SysRoleEntity>()
                .inSql("pid", "select role_pid from sys_user_role where user_pid = " + "'" + userPid + "'"));

        return sysRoles;
    }

}